package com.oss.config;

import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
 * 文件上传配置
 * @author chengqiang
 */
@Configuration
public class MulterFileConfig {
    /**
     * 文件上传配置
     * @return 返回配置信息
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大
        DataSize maxFileSize = DataSize.parse("50MB");
        factory.setMaxFileSize(maxFileSize); //KB,MB
        /// 设置总上传数据总大小
        DataSize maxRequestSize = DataSize.parse("100MB");
        factory.setMaxRequestSize(maxRequestSize);
        return factory.createMultipartConfig();
    }
}
